package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.vo.ReservationCountByTimeVo;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;
import java.util.List;
import com.zzyl.nursing.domain.Reservation;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 预约信息表Mapper接口
 * 
 * @author Tomorrow
 * @date 2025-01-10
 */
@Mapper
public interface ReservationMapper extends BaseMapper<Reservation>
{
    /**
     * 查询预约信息表
     * 
     * @param id 预约信息表主键
     * @return 预约信息表
     */
    public Reservation selectReservationById(Long id);

    /**
     * 查询预约信息表列表
     * 
     * @param reservation 预约信息表
     * @return 预约信息表集合
     */
    public List<Reservation> selectReservationList(Reservation reservation);

    /**
     * 新增预约信息表
     * 
     * @param reservation 预约信息表
     * @return 结果
     */
    public int insertReservation(Reservation reservation);

    /**
     * 修改预约信息表
     * 
     * @param reservation 预约信息表
     * @return 结果
     */
    public int updateReservation(Reservation reservation);

    /**
     * 删除预约信息表
     * 
     * @param id 预约信息表主键
     * @return 结果
     */
    public int deleteReservationById(Long id);

    /**
     * 批量删除预约信息表
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteReservationByIds(Long[] ids);

    /**
     *查询每个时间段剩余预约次数
     * @param startTime,endTime
     */

    @Select("select time, 6 - COUNT(*) as count from reservation where time between  #{startTime} and #{endTime} and status != 2 group by time")

    List<ReservationCountByTimeVo> countByTime(@Param("startTime")  LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);


/*    @Select("select count(*) from reservation where status = 2 and update_by = #{updateBy} and update_time between #{startTime} and #{endTime}")
    Integer getCancelledReservationCount(@Param("updateBy") Long updateBy,@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);*/
}
